package cn.yiueil.advice;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

/**
 * 更灵活，可以运行到各个阶段
 */
public class Interceptor implements MethodInterceptor {
    @Override
    public Object invoke(MethodInvocation invocation) throws Throwable {
        Object object = null;
        System.out.println("Interceptor log "+ invocation.getMethod().getName() + " start------------");
        try {
            object = invocation.proceed();//执行原始方法
        } catch (Exception e) {
            System.out.println("Interceptor log "+ invocation.getMethod().getName() + " exception------------");
            e.printStackTrace();
        }
        System.out.println("Interceptor log "+ invocation.getMethod().getName() + " end------------");
        return object;
    }
}
